We consider the stability of periodic travelling-wave solutions to a generalized Korteweg–de Vries (gKdV) equation and prove an index theorem relating the number of unstable and potentially unstable eigenvalues to geometric information on the classical mechanics of the travelling-wave ordinary differential equation. We illustrate this result with several examples, including the integrable KdV and modified KdV equations, the L2-critical KdV-4 equation that arises in the study of blow-up and the KdV-½ equation, which is an idealized model for plasmas.